///////////////////////////////查询轨迹的方法群////////////////////////////////////////

var gpsRydQueryDlg = null;

var gpsRydResArray = [];

var gpsShowRydMarkArray = [];

var gpsRydMarkLayer;

function initRydQueryDlg(){
	if(gpsRydQueryDlg)
		return;
	var gpsRydQueryHtml = '<div style="width:340px;height:200px;font-size:11px;font-family:微软雅黑;position:absolute;left:15px;top:40px;">'+
											'<div id="rydQueryConditionBar" style="position:absolute;left:0px;top:0px;width:340px;height:40px;">'+
												'<label>时间范围：</label><input id="rydTimeInputForm" type="text" style="width:120px;height:18px;" class="Wdate" onfocus="WdatePicker({startDate: \'00:00:00\',dateFmt:\'yyyy-MM-dd HH:mm:ss\',alwaysUseStartDate:true})"/> '+
												' — <input id="rydTimeInputTo" style="width:120px;height:18px;" type="text" class="Wdate" onfocus="WdatePicker({startDate:\'00:00:00\',dateFmt:\'yyyy-MM-dd HH:mm:ss\',alwaysUseStartDate:true})"/>'+
												'<br/>'+
												'<input id="queryRydButton" type="button" value="确定" />'+
											'</div>'+
											'<div id="queryRydResultContent" style="width:330px;height:135px;border:1px solid #ABADB3;position:absolute;left:2px;top:55px;overflow-y:auto;overflow-x:hidden;">'+
												'<table id="queryRydResultTable" style="font-size:11px;width:330px;border-collapse: collapse;">'+
													'<tr>'+
														'<td class="queryTd">显示</td><td class="queryTd">序号</td><td class="queryTd">点名称</td><td class="queryTd">定位时间</td>'+
													'</tr>'+
												'</table>'+
											'</div>'+
										'</div>';
	gpsRydQueryDlg = $.dialog({
		title: '任意点查询',
		content: gpsRydQueryHtml,
		dlgDivId: "gpsRydQueryId",
		resize: false,
		max: false,
		left:"250px",
		top:'100px',
		width:'340px',
		height:'200px',
		min:gpsRydQueryDlgMinFunc,
		init:function(){
			//对按钮的监听
			$("#queryRydButton").click(queryRydClickFunction);
		},
		close:gpsRydQueryDlgCloseFunc
	});
}

function gpsRydQueryDlgMinFunc(){
	minDlgByAnimate(gpsRydQueryDlg);
}

function gpsRydQueryDlgCloseFunc(){
	gpsRydQueryDlg = null;
	gpsRydResArray = [];
	gpsShowRydMarkArray = [];
	removeGpsRydMarkLayer();
}

//////点击确定按钮之后的函数
function queryRydClickFunction(){
	var startTime = $("#rydTimeInputForm").val();
	var endTime = $("#rydTimeInputTo").val();
	var obj = {startTime:startTime,endTime:endTime};
	var url = "queryRyd.shtml";
	$.post(url,obj,queryRydCallback);
}

//查询之后的回调
function queryRydCallback(res){
	$(".gpsResultTr").remove();
	res = eval(res);
	gpsRydResArray = res;
	removeGpsRydMarkLayer();
	gpsRydMarkLayer = new OpenLayers.Layer.Markers("gpsRydMarkLayer");
	map.addLayer(gpsRydMarkLayer);
	gpsShowRydMarkArray = new Array(res.length);
	for(var i = 0;i<res.length;i++){
		var name = res[i].mc;
		var timeStr = (res[i].dwsj.year+1900)+"年"+(res[i].dwsj.month+1)+"月"+(res[i].dwsj.date)+"日"+(res[i].dwsj.hours)+"时"+(res[i].dwsj.minutes)+"分"+(res[i].dwsj.seconds)+"秒";
		var appendHtmlStr = '<tr class="gpsResultTr">'+
										'<td class="queryTd"><input type="checkbox" class="gpsRydCheck" id="'+i+'"/></td><td class="queryTd">'+(i+1)+'</td><td class="queryTd">'+name+'</td><td class="queryTd">'+timeStr+'</td>'+
										'</tr>';
		$("#queryRydResultTable").append(appendHtmlStr);
	}
	$(".gpsRydCheck").click(gpsRydCheckClick);
}

//点击checkbox的函数
function gpsRydCheckClick(evt){
	var id = Number(evt.currentTarget.id);
	if(evt.currentTarget.checked){
		var obj = gpsRydResArray[id];
		var size = new OpenLayers.Size(16, 16);
		var icon = new OpenLayers.Icon('image/car.png', size);
		var mark = new OpenLayers.Marker(new OpenLayers.LonLat(obj.jd,obj.wd),icon);
		gpsRydMarkLayer.addMarker(mark);
		gpsShowRydMarkArray[id] = mark;
		map.setCenter(mark.lonlat);
	}else{
		gpsRydMarkLayer.removeMarker(gpsShowRydMarkArray[id]);
	}
}


//删除图层
function removeGpsRydMarkLayer(){
	if(gpsRydMarkLayer){
		map.removeLayer(gpsRydMarkLayer);
		gpsRydMarkLayer = undefined;
	}
}

